<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :lg="3 ">
            <a-form-item label="分类">
              <select-category v-model="queryParam.categoryId"
                               :placeholder="'请选择所属分类'"></select-category>
            </a-form-item>
          </a-col>
          <a-col :lg="3">
            <a-form-item label="品牌">
              <a-select v-model="queryParam.brandId" placeholder="请选择所属品牌">
                <a-select-option :value="item.id" v-for="item in brandList" :key="item.id">
                  {{ item.name }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :lg="4">
            <a-form-item label="价格">
              <a-input-group compact>
                <a-input style=" width: 100px; text-align: center" v-model="queryParam.min" />
                <a-input
                  style=" width: 30px; border-left: 0; pointer-events: none; backgroundColor: #fff"
                  placeholder="~"
                  disabled
                />
                <a-input style="width: 100px; text-align: center; border-left: 0" v-model="queryParam.max" />
              </a-input-group>
            </a-form-item>
          </a-col>
          <a-col :lg="4" style="margin-left: -72px">
            <a-form-item label="关键字">
              <a-input v-model="queryParam.keywords" placeholder="请输入检索关键字" :allowClear="true"></a-input>
            </a-form-item>
          </a-col>
          <a-col :lg="4">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                  <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                  <a-button type="primary" @click="resetSearch" icon="reload" style="margin-left: 8px">重置</a-button>
              </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="skuDefaultImg" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">预览</a>
          <a-divider type="vertical" />
            <a @click="handleEdit(record)">评论</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <sku-info-modal ref="modalForm" @ok="modalFormOk"></sku-info-modal>
  </a-card>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '../../utils/mixin'
import { JeecgListMixin } from '../../mixins/JeecgListMixin'
import SkuInfoModal from './sku/SkuInfoModal.vue'
import SelectCategory from '../../components/compents/SelectCategory.vue'
import { getAction } from '../../api/manage'

export default {
  name: 'SkuInfoList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    SelectCategory,
    SkuInfoModal
  },
  data() {
    return {
      description: 'pms_sku_info管理页面',
      brandList: [],
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '名称',
          align: 'center',
          dataIndex: 'skuName'
        },
        {
          title: '默认图片',
          align: 'center',
          dataIndex: 'skuDefaultImg',
          scopedSlots: { customRender: 'skuDefaultImg' }
        },
        {
          title: '价格',
          align: 'center',
          dataIndex: 'price'
        },
        {
          title: '销量',
          align: 'center',
          dataIndex: 'saleCount'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/product/skuInfo/list',
        delete: '/product/skuInfo/delete',
        initBrandList: '/product/brand/list',
        deleteBatch: '/product/skuInfo/deleteBatch'
      }
    }
  },
  created() {
    this.initBrandList()
  },
  computed: {},
  methods: {
    /**
     * 重置搜索
     */
    resetSearch() {
      this.queryParam = {}
      this.loadData()
    },
    /**
     * 初始化品牌列表
     */
    initBrandList() {
      getAction(this.url.initBrandList).then(res => {
        if (res.success) {
          this.brandList = res.result.records
        } else {
          this.$message.error('获取品牌列表失败!')
        }
      })
    }
  }
}
</script>
<style scoped>
@import '/src/assets/less/common.less';

/deep/ .ant-table-tbody tr {
  height: 50px !important;
}
</style>